package com.video.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.video.common.annotation.Log;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoEducation;
import com.video.system.service.IVideoEducationService;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 学历Controller
 * 
 * @author lyh
 * @date 2021-07-20
 */
@Controller
@RequestMapping("/system/education")
public class VideoEducationController extends BaseController
{
    private String prefix = "system/education";

    @Autowired
    private IVideoEducationService videoEducationService;

    @RequiresPermissions("system:education:view")
    @GetMapping()
    public String education()
    {
        return prefix + "/education";
    }

    /**
     * 查询学历列表
     */
    @RequiresPermissions("system:education:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VideoEducation videoEducation)
    {
        startPage();
        List<VideoEducation> list = videoEducationService.selectVideoEducationList(videoEducation);
        return getDataTable(list);
    }

    /**
     * 导出学历列表
     */
    @RequiresPermissions("system:education:export")
    @Log(title = "学历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VideoEducation videoEducation)
    {
        List<VideoEducation> list = videoEducationService.selectVideoEducationList(videoEducation);
        ExcelUtil<VideoEducation> util = new ExcelUtil<VideoEducation>(VideoEducation.class);
        return util.exportExcel(list, "学历数据");
    }

    /**
     * 新增学历
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学历
     */
    @RequiresPermissions("system:education:add")
    @Log(title = "学历", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VideoEducation videoEducation)
    {
        return toAjax(videoEducationService.insertVideoEducation(videoEducation));
    }

    /**
     * 修改学历
     */
    @GetMapping("/edit/{educationId}")
    public String edit(@PathVariable("educationId") Integer educationId, ModelMap mmap)
    {
        VideoEducation videoEducation = videoEducationService.selectVideoEducationById(educationId);
        mmap.put("videoEducation", videoEducation);
        return prefix + "/edit";
    }

    /**
     * 修改保存学历
     */
    @RequiresPermissions("system:education:edit")
    @Log(title = "学历", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VideoEducation videoEducation)
    {
        return toAjax(videoEducationService.updateVideoEducation(videoEducation));
    }

    /**
     * 删除学历
     */
    @RequiresPermissions("system:education:remove")
    @Log(title = "学历", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(videoEducationService.deleteVideoEducationByIds(ids));
    }
}
